package com.yiwei.hdb.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.yiwei.hdb.R;
import com.yiwei.hdb.adapter.base.ItemAdapter;
import com.yiwei.hdb.model.PrizeListModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyPrizeAdapter extends ItemAdapter<PrizeListModel.DataBean, MyPrizeAdapter.DefaultHolder> {

    private int fstatus;
    private Context context;

    public MyPrizeAdapter(Context context) {
        super(context);
        this.context = context;
    }

    public void setFstatus(int fstatus) {
        this.fstatus = fstatus;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_prize, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        PrizeListModel.DataBean item = getItem(position);
        holder.txtTitle.setText(item.name);
        holder.txtContent.setText(item.description);
        Glide.with(context).load(item.image).into(holder.imgIcon);
        if (fstatus == 1) {
            holder.btnSubmit.setText("立即领取");
            holder.btnSubmit.setShapeSolidColor(0xff4C81FF).setUseShape();
        } else if (fstatus == 2) {
            holder.btnSubmit.setText("已领取");
            holder.btnSubmit.setShapeSolidColor(0xff3BCF8F).setUseShape();
        } else if (fstatus == 3) {
            holder.btnSubmit.setText("已过期");
            holder.btnSubmit.setShapeSolidColor(0xffE4E4EE).setUseShape();
        }
        holder.btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (fstatus == 1) {
                    if (onChooseListener != null) {
                        onChooseListener.onClick(item.id);
                    }
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.btn_submit)
        SuperButton btnSubmit;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String content);
    }
}
